package cn.bx.bid.repository;

import cn.bx.bid.entity.Project;
import cn.bx.bid.entity.RandomName;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface RandomNameRepository extends JpaRepository<RandomName,Long>, JpaSpecificationExecutor<RandomName> {

   //删除参与项目
    public  int deleteByProjectidAndProfessorid(long projid,long profid);

    public List<RandomName> findAllByProfessorid(long profid);
    public List<RandomName> findAllByProjectid(long projid);


    //参加该项目
    @Modifying
    @Query(" update RandomName set bePresent='是' ,replyTime=now(),reason='' where professorid=?1 and projectid=?2")
    public int profRoleProject(long profid,long projid);


    //不参加该项目
    @Modifying
    @Query(" update RandomName set bePresent='否' ,replyTime=now(),reason=?3 where professorid=?1 and projectid=?2")
    public int profnotPresentProject(long profid,long projid,String reason);

  //确定参加该项目的专家人数
    @Query("select count(*) from RandomName where projectid=?1 and bePresent='是'")
    public int getComingProfessors(long projid);



    @Query(" select count(*) from RandomName where projectid=?1 and (bePresent='是' or bePresent!='否')")
    public int getPrentProfessors(long projid);

//        <select id="getProfessorsForChoose" resultType="Professor">
//    select p.id,p.professorname,p.address from professor p
//    where p.id not in(select professorid from randomname where projectid=#{prjid})
//         <if test="category!=null and category!=''">
//    and p.projectcategory like concat('%',#{category},'%')
//         </if>
//    </select>


//    <insert id="saveChoose" parameterType="RandomName">
//    insert into randomname(professorId,projectId,status,createDate,reason,isNotice,bePresent,replyTime,msg)
//    values(#{professorid},#{projectid},#{status},#{createdate},#{reason},#{isNotice},#{bePresent},#{replyTime},#{msg})
//    </insert>




}
